﻿using IM.Easy.Core.Audit;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.Entity.Log
{
    /// <summary>
    /// 请求追踪实体类，记录每个HTTP请求的详细信息
    /// </summary>
    [SugarTable]
    public class RequestTrackingLog : ICreatedAt
    {
        /// <summary>
        /// 主键
        /// </summary>
        [SugarColumn(IsPrimaryKey = true)]
        public Guid Id { get; set; }
        /// <summary>
        /// 请求的唯一追踪ID，用于标识整个请求链路
        /// </summary>
        [SugarColumn(Length = 50)]
        public string TraceIdentifier { get; set; }

        /// <summary>
        /// 请求时间
        /// </summary>
        public DateTime? RequestTime { get; set; }

        /// <summary>
        /// 响应时间
        /// </summary>
        public DateTime? ResponseTime { get; set; }

        /// <summary>
        /// 请求持续时间（毫秒）
        /// </summary>
        public long Duration { get; set; }

        /// <summary>
        /// HTTP请求方法（如GET、POST等）
        /// </summary>
        public string HttpMethod { get; set; }

        /// <summary>
        /// 请求的完整URL
        /// </summary>
        [SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public string Url { get; set; }

        /// <summary>
        /// 接口名称
        /// </summary>
        public string? ActionName { get; set; }

        /// <summary>
        /// 关联接口ID
        /// </summary>
        public long EndpointId { get; set; }

        /// <summary>
        /// 请求参数
        /// </summary>
        [SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public string? Arguments { get; set; }

        /// <summary>
        /// 响应体内容
        /// </summary>
        [SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public string? ResponseBody { get; set; }

        /// <summary>
        /// 客户端IP地址
        /// </summary>
        public string? ClientIP { get; set; }

        /// <summary>
        /// 请求地址
        /// </summary>
        public string? Address { get; set; }

        /// <summary>
        /// 用户ID（如果请求有认证信息）
        /// </summary>
        public long? UserId { get; set; }

        /// <summary>
        /// 操作人
        /// </summary>
        public string? UserName { get; set; }

        /// <summary>
        /// 请求是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 用户代理信息（如浏览器类型、版本等）
        /// </summary>
        public string? UserAgent { get; set; }

        /// <summary>
        /// 操作终端
        /// </summary>
        public string? Terminal { get; set; }

        /// <summary>
        /// 记录创建时间
        /// </summary>
        public DateTime? CreatedAt { get; set; }
    }

}
